{% extends '../base.html' %}

{% block title %} 后台登录 {% end %}

{% block main %}
<div class="page">
  <div class="page-single">
    <div class="container">
      <div class="row">
        <div class="col col-login mx-auto">
          <div class="text-center mb-6">
            <h1>Mason-BLOG</h1>
          </div>
          <form class="card" >
            <div class="card-body p-6">
              <div class="form-group">
                <label class="form-label">账号</label>
                <input type="text" class="form-control" name="username" placeholder="">
              </div>
              <div class="form-group">
                <label class="form-label">密码</label>
                <input type="password" class="form-control" name="password" placeholder="">
              </div>
              <div class="form-group">
                <label class="custom-control custom-checkbox">
                  <input type="checkbox" class="custom-control-input" checked/>
                  <span class="custom-control-label">记住我</span>
                </label>
              </div>
              <div class="form-footer">
                <button type="button" class="btn btn-primary btn-block" onclick="sigin()">登录</button>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>
<script>
  require(["jquery"], function($){
    
  })

  function sigin(){
    let usernameInput = $("input[name=username]").val()
    let passwordInput = $("input[name=password]").val()
    if (usernameInput == "" || passwordInput == ""){
      console.log("输入不能为空！")
      // $(".alert span span").text("输入不能为空！")
      showAlert("alert-danger", "fe-alert-triangle", "输入不能为空！")
      return false
    }
    $.ajax("/admin/login", {
      method: "POST",
      contentType: "application/json",
      dataType: "json",
      headers: {},
      data: JSON.stringify({
        username: usernameInput,
        password: passwordInput
      }),
    }).done(function(data){
      console.log(data)
      if (data["status"]==1){
        
      }else{
        showAlert("alert-danger", "fe-alert-triangle", data["msg"])
        return false
      }
    }).fail(function(xhr, error){

    })
  }

</script>
{% end %}